#include "Spring.h"


LinearSpring::LinearSpring(void)
{
	local = 0;
	remote = 0;
	equilibirum = 1.0f;
	minL = 0.5f;
	maxL = 2.0f;
	k = 1.0f;
}

LinearSpring::LinearSpring(float _length, float _minL, float _maxL, float _k, Particle* _local, Particle* _remote)
{
	local = _local;
	remote = _remote;
	equilibirum = _length;
	minL = _minL;
	maxL = _maxL;
	k = _k;
}

void LinearSpring::update(int delta) {
	float dt = delta/1000.0f;

	//actual length of spring
	Vector3f d = local->position - remote->position;
	float d_length = d.length();
	d.normalize();

	//magnitude of force
	float force = -k*(d_length-equilibirum);

	local->force += d * force;
	remote->force += d * -force;
}

float LinearSpring::getLength() {
	//actual length of spring
	Vector3f d = local->position - remote->position;
	return d.length();
}